﻿#include "widget.h"
#include "ui_widget.h"
#include "inherentlnk.h"
#include "applnk.h"
#include "setting.h"
#include "menuwidget.h"
#include "hubwidget.h"
#include "textedit.h"

#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFile>
#include <QFileDialog>
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QMimeData>
#include <QPainter>
#include <QProcess>
#include <QPropertyAnimation>
#include <QScreen>
#include <QSoundEffect>
#include <QStandardPaths>
#include <QTimer>
#include "setting.h"
#include "windows.h"


const QColor SPLIT_LINE_COLOR = QColor(33, 33, 33, 200);
const int SPLIT_LINE_WIDTH = 2;
const int TIME500 = 500;


QString Widget::program_dir = QApplication::applicationDirPath();  // 程序所在的目录
int Widget::screen_height = 0;
int Widget::screen_width = 0;


bool check_full_screen()
{
    HWND hWnd = GetForegroundWindow();
    BOOL ret = IsZoomed(hWnd);
    return (TRUE == ret ? true : false);

    //bool bFullScreen = false;
    //HWND hWnd = GetForegroundWindow();
    //RECT rcApp, rcDesk;
    //GetWindowRect(GetDesktopWindow(), &rcDesk);
    //if (hWnd != GetDesktopWindow() && hWnd != GetShellWindow())
    //{
    //	GetWindowRect(hWnd, &rcApp);
    //	if (rcApp.left <= rcDesk.left && rcApp.top <= rcDesk.top && rcApp.right >= rcDesk.right && rcApp.bottom >= rcDesk.bottom)
    //		bFullScreen = true;
    //}
    //return bFullScreen;
}

// WindowStaysOnTopHint 让窗口永远置顶
// FramelessWindowHint 让窗口无边框
// Tool 让窗口不显示在任务视图中
Widget::Widget(QWidget *parent)
    : QWidget(parent, Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint),
      this_is_move_window(false),
      ui(new Ui::Widget),
      menu_ptr(nullptr),
      is_hide(false),
      temp_show(false),
      mouse_is_in(false)
{
    ui->setupUi(this);
    QDir::setCurrent(get_program_dir());

    auto screen = QGuiApplication::primaryScreen();
    screen_height = screen->size().height();
    screen_width = screen->size().width();

    setAttribute(Qt::WA_TranslucentBackground);  // 设置窗口背景透明

    // 隐藏任务栏
    ShowWindow(FindWindow(L"Shell_TrayWnd", NULL), SW_HIDE);
    // 接收鼠标拖动事件
    setAcceptDrops(true);

    lnk_handler = new LNKHandler(get_program_dir() + "/links/", get_program_dir() + "/init.xq", this);

    // 每隔一段时间查询一下鼠标位置
    QTimer *t = new QTimer(this);
    t->start(200);
    connect(t, &QTimer::timeout, this, [this]()
    {
        bool check_result = check_full_screen();

        // 检测别的程序是否全屏
        if (check_result)
        {
            if (! is_hide)
            {
                // 播放下降动画
                animation_down();
                is_hide = true;
            }
        }
        else  // 没有窗口全屏时，显示本控件
        {
            if (is_hide)
            {
                if (temp_down_timer->isActive())  // 把窗口不全屏时，正在临时显示
                {
                    animation_up();
                    temp_down_timer->stop();
                }
                else
                    animation_up();

                is_hide = false;
            }
        }

        // 检测鼠标是否触底
        auto pos = QCursor().pos();
        if (pos.y() + 1 >= screen_height)
        {
            if (check_result)
            {
                if (! temp_show)
                {
                    if (temp_down_timer->isActive())
                    {
                        temp_down_timer->stop();
                        temp_down_timer->start(2000);
                    }
                    else
                    {
                        temp_show = true;
                        animation_half();
                    }
                }
            }
            else
            {
                if (is_hide)
                {
                    animation_up();
                    is_hide = false;
                }
            }
        }
        else
        {
            if (temp_show)  // 如果鼠标不放在底部了，并且正在临时显示，就在 2 秒之后隐藏本窗口
            {
                // 过一段时间移下去
                temp_down_timer->start(2000);  // 保持两秒
                temp_show = false;
            }
        }

        // 鼠标进入了本窗口
        if (mouse_is_in)
        {
            if (temp_down_timer->isActive())
            {
                temp_down_timer->stop();
                temp_down_timer->start(2000);
            }
        }
    });

    // 临时显示开始隐藏的计时器
    temp_down_timer = new QTimer(this);
    connect(temp_down_timer, &QTimer::timeout, this, [this]()
    {
        temp_down_timer->stop();
        animation_down();
    });

    // 用户拖拽窗口，计时回到原位的计时器
    timer_back_ = new QTimer(this);
    connect(timer_back_, &QTimer::timeout, this, [this]()
    {
        timer_back_->stop();
        // 回到原位的动画
        animation_up();
    });

    // 初始化声音
    init_sounds();

    // 初始化窗口和窗口上的控件
    int wd = setting_handler_->get_dx() * (4 + lnk_handler->get_size()) + setting_handler_->get_border_size();
    if (setting_handler_->get_show_clock())
        wd += setting_handler_->get_lnk_size() * 1.8 + setting_handler_->get_border_size() * 2;

    resize(wd, setting_handler_->get_widget_height());
    init_lnks();
    move((screen_width - wd) / 2, screen_height);
}

// 初始化声音
void Widget::init_sounds()
{
    delete_sound = new QSoundEffect(this);
    delete_sound->setSource(QUrl::fromLocalFile(":/sounds/delete.wav"));
    delete_sound->setLoopCount(1);
    delete_sound->setVolume(1.0f);
}

// 初始化
void Widget::init_lnks()
{
    // 添加最左侧的 hub 按钮
    hub_lnk = new HubLNK(this);
    hub_lnk->show();
    connect(hub_lnk, &HubLNK::left_clicked, [this]()
    {
        open_hub(hub_lnk);
    });
    connect(hub_lnk, &HubLNK::right_clicked, [this]()
    {
        change_menu_ptr({"打开", "", "取消"});
        menu_ptr->move(x() + hub_lnk->x() + (hub_lnk->width() - menu_ptr->width()) / 2, y() - menu_ptr->height() - 10);
        menu_ptr->show();

        // 连接该右键菜单的点击事件
        connect(menu_ptr, &MenuWidget::clicked_item, menu_ptr, [=](QString word)
        {
            change_menu_ptr({});
            if (word == "打开")
            {
                open_hub(hub_lnk);
            }
        });
    });

    // 添加我的电脑按钮
    my_computer_lnk = new InherentLNK(":/svgs/my_computer.svg", "此电脑", this);
    my_computer_lnk->show();
    connect(my_computer_lnk, &InherentLNK::left_clicked, [=]()
    {
        change_menu_ptr({});  // 如果有打开的菜单，则关闭

        auto p = new QProcess(this);
        p->startDetached("explorer.exe", {"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"});
    });
    connect(my_computer_lnk, &InherentLNK::right_clicked, [=]()
    {
        change_menu_ptr({"打开我的电脑", "属性", "管理", "", "取消"});
        menu_ptr->move(x() + my_computer_lnk->x() + (my_computer_lnk->width() - menu_ptr->width()) / 2, y() - menu_ptr->height() - 10);
        menu_ptr->show();

        // 连接该右键菜单的点击事件
        connect(menu_ptr, &MenuWidget::clicked_item, [=](QString word)
        {
            change_menu_ptr({});
            auto p = new QProcess(this);
            if (word == "打开我的电脑")
            {
                p->startDetached("explorer.exe", {"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"});
            }
            else if (word == "属性")
            {
                p->startDetached("control.exe", {"system"});
            }
            else if (word == "管理")
            {
                p->startDetached("compmgmt.msc");
            }
        });
    });

    // 添加回收站按钮
    rubbish_lnk = new InherentLNK(":/svgs/rubbish_close.svg", "回收站", this, true);
    rubbish_lnk->show();
    connect(rubbish_lnk, &InherentLNK::left_clicked, [=]()
    {
        change_menu_ptr({});  // 如果有打开的菜单，则关闭
        auto p = new QProcess(this);
        p->startDetached("explorer.exe", {"::{645FF040-5081-101B-9F08-00AA002F954E}"});
    });
    connect(rubbish_lnk, &InherentLNK::right_clicked, this, [=]()
    {
        change_menu_ptr({"打开回收站", "清空回收站", "", "取消"});
        menu_ptr->move(x() + rubbish_lnk->x() + (rubbish_lnk->width() - menu_ptr->width()) / 2, y() - menu_ptr->height() - 10);
        menu_ptr->show();

        // 连接该右键菜单的点击事件
        connect(menu_ptr, &MenuWidget::clicked_item, menu_ptr, [=](QString word)
        {
            change_menu_ptr({});
            if (word == "打开回收站")
            {
                auto p = new QProcess();
                p->startDetached("explorer.exe", {"::{645FF040-5081-101B-9F08-00AA002F954E}"});
            }
            else if (word == "清空回收站")
            {
//                SHEmptyRecycleBin(hand, NULL, SHERB_NOCONFIRMATION || SHERB_NOPROGRESSUI || SHERB_NOSOUND);
                SHEmptyRecycleBin(NULL, NULL,  SHERB_NOCONFIRMATION);  // SHERB_NOCONFIRMATION表示不显示确认删除对话框
                rubbish_lnk->change_icon("rubbish_close.svg");
                rubbish_lnk->set_have_rubbish(false);
                delete_sound->play();
            }
        });
    });
    // 拖出去是清空回收站
    connect(rubbish_lnk, &InherentLNK::drag_out, [=]()
    {
        SHEmptyRecycleBin(NULL, NULL,  SHERB_NOCONFIRMATION);
        rubbish_lnk->change_icon(":/svgs/rubbish_close.svg");
        rubbish_lnk->set_have_rubbish(false);
        delete_sound->play();
    });
    // 没有拖到外面，则回到原位
    connect(rubbish_lnk, &InherentLNK::not_drag_out, [=]()
    {
//        rubbish_lnk->move(my_computer_lnk->x() + DX, BORDER_SIZE);  // 移到我的电脑后面
    });

    // 添加设置按钮
    setting_lnk = new InherentLNK(":/images/setting.png", "设置", this);
    setting_lnk->show();
    connect(setting_lnk, &InherentLNK::left_clicked, [this]()
    {
        change_menu_ptr({});  // 如果有打开的菜单，则关闭
        Setting* setting = Setting::get_instance();
        // 设置保存按钮按下之后要刷新主界面
        connect(setting, &Setting::setting_saved, this, [this]()
        {
            refresh_all();
            HubWidget::get_instance()->resize(SettingHandler::get_instance()->get_border_size() + 10 * SettingHandler::get_instance()->get_dx(), SettingHandler::get_instance()->get_border_size() + 5 * SettingHandler::get_instance()->get_dx() + 10);  // 加的10是给底部箭头留空间
        });
        setting->show();
        setting->animation_show();
    });
    connect(setting_lnk, &InherentLNK::right_clicked, [=]()
    {
        change_menu_ptr({"打开设置", "打开系统设置", "", "关机", "重新启动", "睡眠", "注销", "", "取消", "显示任务栏", "隐藏任务栏", "", "关闭程序"});
        menu_ptr->move(x() + setting_lnk->x() + (setting_lnk->width() - menu_ptr->width()) / 2, y() - menu_ptr->height() - 10);
        menu_ptr->show();

        // 连接该右键菜单的点击事件
        connect(menu_ptr, &MenuWidget::clicked_item, [=](QString word)
        {
            change_menu_ptr({});
            if (word == "关闭程序")
            {
                // 播放下降动画
                animation_down();
                QTimer* timer = new QTimer(this);
                connect(timer, &QTimer::timeout, this, [this]()
                {
                    close_and_do_something();
                });
                timer->start(TIME500);
            }
            else if (word == "打开设置")
            {
                Setting* setting = Setting::get_instance();
                // 设置保存按钮按下之后要刷新主界面
                connect(setting, &Setting::setting_saved, this, [this]()
                {
                    refresh_all();
                    HubWidget::get_instance()->resize(SettingHandler::get_instance()->get_border_size() + 10 * SettingHandler::get_instance()->get_dx(), SettingHandler::get_instance()->get_border_size() + 5 * SettingHandler::get_instance()->get_dx() + 10);  // 加的10是给底部箭头留空间
                });
                setting->show();
                setting->animation_show();
            }
            else if (word == "打开系统设置")
            {
                auto p = new QProcess(this);
                p->startDetached("control.exe", {"system"});
            }
            else if (word == "注销")
            {
                auto p = new QProcess(this);
                p->startDetached("C:/WINDOWS/system32/shutdown.exe", {"-l"});
            }
            else if (word == "睡眠")
            {
                auto p = new QProcess(this);
                p->startDetached("C:/WINDOWS/system32/rundll32.exe", {"powrprof.dll,SetSuspendState"});
            }
            else if (word == "关机")
            {
                auto p = new QProcess(this);
                p->startDetached("C:/WINDOWS/system32/shutdown.exe", {"-s", "-t", "0"});
            }
            else if (word == "重新启动")
            {
                auto p = new QProcess(this);
                p->startDetached("C:/WINDOWS/system32/shutdown.exe", {"-r", "-t", "0"});
            }
            else if (word == "显示任务栏")
            {
                ShowWindow(FindWindow(L"Shell_TrayWnd", L""), SW_SHOW);
            }
            else if (word == "隐藏任务栏")
            {
                ShowWindow(FindWindow(L"Shell_TrayWnd", L""), SW_HIDE);
            }
        });
    });

    // 添加时钟
    clock_ = new Clock(this);
    if (setting_handler_->get_show_clock())
    {
        clock_->show();
    }

    refresh_all();
}

void Widget::open_hub(HubLNK* hub_lnk)
{
    int new_x = x() + hub_lnk->x() + (hub_lnk->width() - HubWidget::get_instance()->width()) / 2;
    if (new_x < 10)
        new_x = 10;
    else if (new_x > screen_width - TextEdit::width_ - 10)
        new_x = screen_width - TextEdit::width_ - 10;

    if (HubWidget::get_instance()->isHidden())
    {
        int center_x = x() + hub_lnk->x() + hub_lnk->width() / 2 - new_x;
        HubWidget::get_instance()->move(new_x, y() - HubWidget::get_instance()->height() - 10);
        HubWidget::get_instance()->update_and_show(center_x);
    }
    else
    {
        HubWidget::get_instance()->hide();
    }
}

void Widget::change_menu_ptr(const QList<QString> &item_list)
{
    if (menu_ptr)
    {
        menu_ptr->hide();
        menu_ptr->deleteLater();
        menu_ptr = nullptr;
    }

    if (item_list.size() != 0)  // 有重新打开的菜单
    {
        menu_ptr = new MenuWidget(item_list);
    }
}

void Widget::refresh_all()
{
    int lnk_x = setting_handler_->get_border_size();
    // 显示左侧的固定控件
    hub_lnk->move(lnk_x, setting_handler_->get_border_size());
    hub_lnk->set_size(QSize(setting_handler_->get_lnk_size(), setting_handler_->get_lnk_size()));
    lnk_x += setting_handler_->get_dx();

    // 遍历lnk列表，更新每个控件
    for (const auto & applnk : lnk_handler->get_list())
    {
        applnk->move(lnk_x, setting_handler_->get_border_size());
        applnk->set_size(setting_handler_->get_lnk_size(), setting_handler_->get_lnk_size());
        applnk->show();
        lnk_x += setting_handler_->get_dx();
    }

    // 遍历右侧自带的控件
    my_computer_lnk->move(lnk_x, setting_handler_->get_border_size());
    my_computer_lnk->set_size(setting_handler_->get_lnk_size(), setting_handler_->get_lnk_size());
    lnk_x += setting_handler_->get_dx();
    rubbish_lnk->move(lnk_x, setting_handler_->get_border_size());
    rubbish_lnk->set_size(setting_handler_->get_lnk_size(), setting_handler_->get_lnk_size());
    lnk_x += setting_handler_->get_dx();
    setting_lnk->move(lnk_x, setting_handler_->get_border_size());
    setting_lnk->set_size(setting_handler_->get_lnk_size(), setting_handler_->get_lnk_size());
    lnk_x += setting_handler_->get_dx();

    if (setting_handler_->get_show_clock())
    {
        clock_->move(lnk_x, setting_handler_->get_border_size());
        clock_->set_height(setting_handler_->get_lnk_size());
        lnk_x += setting_handler_->get_lnk_size() * 1.8 + setting_handler_->get_border_size() * 2;
    }

    // 如果窗口宽度发生改变，则播放动画并改变大小
    if (lnk_x != width())
    {
        QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
        animation->setDuration(500);
        animation->setStartValue(QRect(x(), y(), width(), setting_handler_->get_widget_height()));
        animation->setEndValue(QRect((screen_width - lnk_x) / 2, y(), lnk_x, setting_handler_->get_widget_height()));
        animation->start();
    }

    update();
}

void Widget::open_file(const QString &absolute_path, AppLNK* app_lnk)
{
    if (app_lnk != nullptr && absolute_path.endsWith(".txt"))  // 这些后缀名的文件用自带的文本编辑器打开
    {
        int new_x = x() + app_lnk->x() + (app_lnk->width() - TextEdit::width_) / 2;
        if (new_x < 10)
            new_x = 10;
        else if (new_x > screen_width - TextEdit::width_ - 10)
            new_x = screen_width - TextEdit::width_ - 10;

        int pointer_center_x = x() + app_lnk->x() + app_lnk->width() / 2 - new_x;
        TextEdit* te = new TextEdit(absolute_path, pointer_center_x, this);
        te->move(new_x, y() - te->height() - 10);
        te->show();
    }
    else
    {
        bool ret = QDesktopServices::openUrl(QUrl::fromLocalFile(absolute_path));
        if (!ret)
            QMessageBox::critical(this, "打开错误", "我们遇到了一些意想不到的错误，\n打开 " + absolute_path + " 失败");
    }
}

bool Widget::start_in_cmd(const QString &cmd_input)
{
    // 把QString变成wstring
    int num = MultiByteToWideChar(CP_UTF8, 0, cmd_input.toStdString().c_str(), -1, NULL, 0);
    wchar_t *wide = new wchar_t[num];
    MultiByteToWideChar(CP_UTF8, 0, cmd_input.toStdString().c_str(), -1, wide, num);
    std::wstring wstrCmdCopy(wide);
    delete[] wide;

    STARTUPINFO si = {0, nullptr, nullptr, nullptr, DWORD(), DWORD(), DWORD(), DWORD(), DWORD(), DWORD(), DWORD(), DWORD(), WORD(), WORD(), nullptr, nullptr, nullptr, nullptr};
    PROCESS_INFORMATION pi = {0, nullptr, DWORD(), DWORD()};
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_SHOWNORMAL;
    BOOL bRet = CreateProcess(NULL, (LPWSTR)wstrCmdCopy.c_str(), NULL, NULL, FALSE,
                CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi);
    if (bRet == FALSE)
        return false;

    CloseHandle(pi.hThread);
    // 无限期等待线程执行完毕, 主线程被挂起
    // WaitForSingleObject(pi.hProcess, INFINITE);
    DWORD dwExitCode;
    GetExitCodeProcess(pi.hProcess, &dwExitCode);
    CloseHandle(pi.hProcess);

    return true;
}

void Widget::animation_up()
{
    int yy = screen_height - setting_handler_->get_margin_bottom() - setting_handler_->get_widget_height();
    QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
    animation->setDuration(TIME500);
    animation->setStartValue(QPoint(x(), y()));
    animation->setEndValue(QPoint((screen_width - width()) / 2, yy));
    animation->setEasingCurve(QEasingCurve::InOutQuad);
    animation->start();
}

void Widget::animation_half()
{
    int yy = screen_height - setting_handler_->get_widget_height();
    QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
    animation->setDuration(TIME500);
    animation->setStartValue(QPoint(x(), y()));
    animation->setEndValue(QPoint(x(), yy));
    animation->setEasingCurve(QEasingCurve::InOutQuad);
    animation->start();
}

void Widget::animation_down()
{
    QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
    animation->setDuration(TIME500);
    animation->setStartValue(QPoint(x(), y()));
    animation->setEndValue(QPoint(x(), screen_height));
    animation->setEasingCurve(QEasingCurve::InOutQuad);
    animation->start();
}

void Widget::paintEvent(QPaintEvent*)
{
    /*画登陆界面的圆角矩形背景*/
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QPen pen(setting_handler_->get_border_color());
    pen.setWidth(1);
    painter.setPen(pen);
    QBrush brush(setting_handler_->get_background_color());
    painter.setBrush(brush);

    QRectF rect(0, 0, this->width(), this->height());
    painter.drawRoundedRect(rect, setting_handler_->get_widget_radius(), setting_handler_->get_widget_radius());
}

void Widget::dragEnterEvent(QDragEnterEvent *event)
{
    event->acceptProposedAction();    // 接收拖拽信号
}

// 文件路径可能要改
void Widget::dropEvent(QDropEvent *event)
{
    auto index = (event->position().x() + setting_handler_->get_lnk_size() / 2) / setting_handler_->get_dx() - 1;
    if (index > lnk_handler->get_size())
        index = lnk_handler->get_size();

    // 如果拖到了hub图标上面
    bool to_hub = false;
    if (QRect(hub_lnk->x(), hub_lnk->y(), hub_lnk->width(), hub_lnk->height()).contains(event->position().x(), event->position().y()))
        to_hub = true;

    for (const auto &url : event->mimeData()->urls())
    {
        // 添加
        QString absolute_path = url.toLocalFile();
        if (to_hub)
            HubWidget::get_instance()->push_back_lnk(absolute_path);
        else
            lnk_handler->add_lnk(index, absolute_path);
    }

    refresh_all();
}

// 鼠标拖入
void Widget::enterEvent(QEnterEvent *)
{
    mouse_is_in = true;
}

// 鼠标离开
void Widget::leaveEvent(QEvent *)
{
    mouse_is_in = false;
}

void Widget::mousePressEvent(QMouseEvent *ev)
{
    auto pos = ev->pos();
    if (pos.x() >= clock_->x() && pos.x() <= clock_->x() + clock_->width())
    {
        this_is_move_window = true;
        press_y = pos.y();
    }
}

void Widget::mouseMoveEvent(QMouseEvent *ev)
{
    if (this_is_move_window)
    {
        auto global_pos = ev->globalPosition();  // 鼠标移动时，获取相对于显示器左上角的位置
        move(x(), global_pos.y() - press_y);
    }
}

void Widget::mouseReleaseEvent(QMouseEvent *)
{
    if (this_is_move_window)
    {
        this_is_move_window = false;
        timer_back_->start(setting_handler_->get_back_time() * 1000);
    }
}

void Widget::show_top()
{
    #ifdef Q_OS_WIN32  // windows必须加这个，不然windows10 会不起作用，具体参看activateWindow 函数的文档
    HWND hForgroundWnd = GetForegroundWindow();
    DWORD dwForeID = ::GetWindowThreadProcessId(hForgroundWnd, NULL);
    DWORD dwCurID = ::GetCurrentThreadId();
    ::AttachThreadInput(dwCurID, dwForeID, TRUE);
    ::SetForegroundWindow((HWND) winId());
    ::AttachThreadInput(dwCurID, dwForeID, FALSE);
    #endif // MAC_OS

    // 老方法
//    setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
//    show();
//    setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
//    show();
}

// 释放开辟在堆区的控件
void Widget::close_and_do_something()
{
    // 重新显示任务栏
    ShowWindow(FindWindow(L"Shell_TrayWnd", NULL), SW_SHOW);
    QApplication::exit(0);
}

Widget::~Widget()
{
    qDebug() << "主界面销毁了";
    // 重新显示任务栏
    ShowWindow(FindWindow(L"Shell_TrayWnd", NULL), SW_SHOW);
    delete ui;
}
